import 'dart:convert';

import 'api_responseg.dart';

class ApiResponse<T> {
  int? code;
  String? msg;
  T? data;

  ApiResponse();

  factory ApiResponse.fromJson(Map<String, dynamic> json) =>
      $ApiResponseFromJson<T>(json);

  Map<String, dynamic> toJson() => $ApiResponseToJson(this);

  bool isSuccess() => code == 0;
  bool isEmpty() {
    if (data == null) {
      return true;
    } else {
      if (data is List) {
        return (data as List).isEmpty;
      }
      return false;
    }
  }

  bool noMoreData(int pageSize) {
    if (data == null) {
      return true;
    } else {
      if (data is List) {
        return (data as List).length < pageSize;
      }
      return false;
    }
  }

  @override
  String toString() {
    return jsonEncode(this);
  }
}
